package com.store.app.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.store.app.R;
import com.store.app.bean.GoodsListNewBean;

import java.util.List;
public class GoodsAdapter extends BaseAdapter {
    private List<GoodsListNewBean> goodsList;
    private Context context;


    public GoodsAdapter(List<GoodsListNewBean> goodsList, Context context) {
        this.goodsList = goodsList;
        this.context = context;
    }

    @Override
    public int getCount() {
        return goodsList.size();
    }

    @Override
    public Object getItem(int position) {
        return goodsList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.item_goods, null);
            //viewHolder.ivGoods = (ImageView) convertView.findViewById(R.id.iv_goods);
            //viewHolder.tvGoods = (TextView) convertView.findViewById(R.id.tv_goods);
            viewHolder.tvBarcode = (TextView) convertView.findViewById(R.id.tv_barcode);
            viewHolder.tvName = (TextView) convertView.findViewById(R.id.tv_name);
            viewHolder.tvSpec = (TextView) convertView.findViewById(R.id.tv_spec);
            viewHolder.tvVender = (TextView) convertView.findViewById(R.id.tv_vender);
            viewHolder.tvCategory = (TextView) convertView.findViewById(R.id.tv_category);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

            //viewHolder.ivGoods.setVisibility(View.VISIBLE);
            //����ͼƬ
            //viewHolder.tvGoods.setVisibility(View.GONE);

        if(!TextUtils.isEmpty(goodsList.get(position).getBarcode())){
            viewHolder.tvBarcode.setText(goodsList.get(position).getBarcode());
        }else{
            viewHolder.tvBarcode.setText("-");
        }
        if(!TextUtils.isEmpty(goodsList.get(position).getBarcode())){
            viewHolder.tvBarcode.setText(goodsList.get(position).getBarcode());
        }else{
            viewHolder.tvBarcode.setText("-");
        }
        if(!TextUtils.isEmpty(goodsList.get(position).getGoods_name())){
            viewHolder.tvName.setText(goodsList.get(position).getGoods_name());
        }else{
            viewHolder.tvName.setText("-");
        }
        if(!TextUtils.isEmpty(goodsList.get(position).getSale_unit())){
            viewHolder.tvSpec.setText(goodsList.get(position).getSale_unit());
        }else{
            viewHolder.tvSpec.setText("-");
        }
        if(!TextUtils.isEmpty(goodsList.get(position).getSale_qty())){
            viewHolder.tvVender.setText(goodsList.get(position).getSale_qty());
        }else{
            viewHolder.tvVender.setText("-");
        }
        if(!TextUtils.isEmpty(goodsList.get(position).getMarket_price() + "")){
            viewHolder.tvCategory.setText(goodsList.get(position).getMarket_price() + "");
        }else{
            viewHolder.tvCategory.setText("-");
        }

        return convertView;
    }


    class ViewHolder {
        //private ImageView ivGoods;
        //private TextView tvGoods;
        private TextView tvBarcode;
        private TextView tvName;
        private TextView tvSpec;
        private TextView tvVender;
        private TextView tvCategory;
    }
}
